#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main() 
{
    int year = 0, m = 0, day = 0;
    while (scanf("%d %d", &year, &m) == 2) 
    {
        if (m == 2) {
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 
            {
                day = 29;
            }
            else 
            {
                day = 28;
            }
        }
        else if ((m % 2 == 1 && m < 8) || (m % 2 == 0 && m >= 8)) 
        {
            day = 31;
        }
        else 
        {
            day = 30;
        }
        printf("%d\n", day);
    }

    return 0;
}